<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2025/7/22 星期二
  Time: 16:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <base href="${pageContext.request.contextPath}/" />
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="static/bootstrapvalidator/css/bootstrapValidator.css"
          rel="stylesheet">

    <script src="static/jquery/jquery-1.10.2.min.js"></script>
    <script src="static/bootstrap-3.3.5/js/bootstrap.js"></script>
    <script src="static/bootstrapvalidator/js/bootstrapValidator.js"></script>


</head>
<body>


<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">编辑部门信息</h4>
    </div>

    <div class="panel-body">
        <form action="hr/zz-department/addDept" id="myform" method="post"
              class="form-horizontal" role="form">
            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="deptName" class="col-md-4 control-label">部门名称</label>
                    <div class="col-md-8">
                        <input type="hidden" id="oid" name="oid" value="">
                        <input type="text" id="deptName" name="deptName"
                               class="form-control" placeholder="请输入部门名称"
                               value="">
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="phone" class="col-md-4 control-label">部门电话</label>
                    <div class="col-md-8">
                        <input type="text" id="phone" name="phone" class="form-control"
                               placeholder="请输入部门电话" value="">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="parentoid" class="col-md-4 control-label">上级部门</label>
                    <div class="col-md-8">
                        <select name="parentoid" class="form-control" id="parentoid">
                            <option value="">--请选择--</option>
                            <c:forEach items="${parents}" var="parent">
                                <option value="${parent.oid}">${parent.deptName}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="fax" class="col-md-4 control-label">部门传真</label>
                    <div class="col-md-8">
                        <input type="text" id="fax" name="fax" class="form-control"
                               placeholder="请输入部门传真" value="">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="manager" class="col-md-4 control-label">部门经理</label>
                    <div class="col-md-8">
                        <input type="hidden" id="manager" name="manager"
                               value="">

                        <div class="input-group">
                            <input type="text" id="managername" name="managername"
                                   readonly="readonly" class="form-control" placeholder="请选择部门经理"
                                   value=""> <span
                                class="input-group-btn">
									<button class="btn btn-info" type="button"
                                            data-toggle="modal" data-target="#selectempModal">请选择</button>
								</span>
                        </div>
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="email" class="col-md-4 control-label">部门邮箱</label>
                    <div class="col-md-8">
                        <input type="text" id="email" name="email" class="form-control"
                               placeholder="请输入部门邮箱" value="">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="zipcode" class="col-md-4 control-label">部门邮编</label>
                    <div class="col-md-8">
                        <input type="text" id="zipcode" name="zipcode"
                               class="form-control" placeholder="请输入部门邮编"
                               value="">
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="address" class="col-md-4 control-label">部门地址</label>
                    <div class="col-md-8">
                        <input type="text" id="address" name="address"
                               class="form-control" placeholder="请输入部门地址"
                               value="">
                    </div>
                </div>
            </div>


            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="description" class="col-md-4 control-label">部门介绍</label>
                    <div class="col-md-8">
							<textarea class="form-control" id="description"
                                      name="description" rows="5" placeholder="请输入部门介绍"></textarea>
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="status" class="col-md-4 control-label">部门状态</label>
                    <div class="col-md-8" id="status">
                        <label class="radio-inline">
                            <input type="radio" name="status"  value="Y">可用
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="status"  value="N">不可用
                        </label>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <label for="jobs" class="col-md-2 control-label">部门职位&nbsp;</label>
                    <div class="col-md-9" id="jobs">

                        <label class="checkbox-inline col-xs-2">


                            <input type="checkbox" name="jobsid"  value="1">董事
                        </label>

                        <label class="checkbox-inline col-xs-2">


                            <input type="checkbox" name="jobsid"  value="2">总经理
                        </label>

                        <label class="checkbox-inline col-xs-2">


                            <input type="checkbox" name="jobsid"  value="3">经理
                        </label>

                        <label class="checkbox-inline col-xs-2">


                            <input type="checkbox" name="jobsid"  value="4">职员
                        </label>

                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <div class="col-md-10  col-md-offset-2">
                        <a type="button" href="javascript:history.back()" class="btn btn-info">返回</a>
                        <button type="submit" id="editdeptbtn" class="btn btn-success">提交信息</button>
                        <button type="reset" id="resetbtn" class="btn btn-default">取消操作</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>



<div class="modal fade" id="selectempModal" tabindex="-1" role="dialog" aria-labelledby="selectempModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="selectempModalLabel">选择员工</h4>
            </div>
            <div class="modal-body">
                <form action="" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="dept" class="col-md-4 control-label">所属部门</label>
                        <div class="col-md-5">
                            <select name="dept" class="form-control" id="dept">
                                <option value="">--请选择--</option>
                                <c:forEach items="${parents}" var="parent">
                                    <option value="${parent.oid}">${parent.deptName}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="job" class="col-md-4 control-label">所属职位</label>
                        <div class="col-md-5">
                            <select name="job" class="form-control" id="job">
                                <option value="">--请选择--</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="emp" class="col-md-4 control-label">员工信息</label>
                        <div class="col-md-5">
                            <select name="emp" class="form-control" id="emp" size="10">

                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="sub" class="btn btn-primary">确认选择</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function(){

        //当部门下拉框发生改变时，发送异步请求得到对应部门中的职位
        $("#dept").change(function(){
            $("#job")[0].options.length=1;
            $("#emp")[0].options.length=0;
            //若选择的值为空则返回
            if(this.value==""){
                return;
            }
            $.getJSON("hr/zz-department-job/listDeptJobUseSelect",{deptid:this.value},function(listjob){
                var job = $("#job")[0];
                job.options.length=1;
                for(var i=0;i<listjob.length;i++){
                    var job1 = listjob[i];
                    job.options.add(new Option(job1.jobName,job1.jobid));
                }
            });

            //根据部门id和职位id查询下属员工
            $.getJSON("hr/emp/listEmpUseSelect",{deptid:$("#dept").val()},function(emps){
                var emp = $("#emp")[0];
                emp.options.length=0;
                for(var i=0;i<emps.length;i++){
                    var e = emps[i];
                    emp.options.add(new Option(e.empName,e.oid));
                }
            });
        });

        $("#job").change(function(){
            $.getJSON("hr/emp/listEmpUseSelect",{deptid:$("#dept").val(),jobid:this.value},function(emps){
                var emp = $("#emp")[0];
                emp.options.length=0;
                for(var i=0;i<emps.length;i++){
                    var e = emps[i];
                    emp.options.add(new Option(e.empName,e.oid));
                }
            });
        });

        $("#sub").click(function(){
            var eid=$("#emp").val();
            if(eid!=null){
                var empName=$("#emp option:selected").text();
                setempvalue(eid,empName);
                $('#selectempModal').modal('hide');
            }else{
                alert("请选择员工");
            }

        });

        $('#selectempModal').on('show.bs.modal',function() {
            $("#dept").val("");
            $("#job")[0].options.length=1;
            $("#emp")[0].options.length=0;
        });
    });
</script>






<script type="text/javascript">
    $(document).ajaxError(function(event,xhr) {
        if(xhr.status=="403"){//没有权限
            document.location.href = xhr.getResponseHeader("url");
        }else if(xhr.status!="200"){
            //alert("服务器错误!");
            console.log("服务器错误!");
        }
    });
</script>

<script type="text/javascript">
    function setempvalue(eid, empName) {
        $("#manager").val(eid);
        $("#managername").val(empName);
    }
</script>
</body>


<script type="text/javascript">
    $(document).ready(function() {
        $("#myform").bootstrapValidator({
            message : 'This value is not valid',
            feedbackIcons : {/*input状态样式图片*/
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            fields : {
                deptName : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '部门名称不能为空'

                        },
                        stringLength : {
                            min : 2,
                            max : 20,
                            message : '部门名称长度需在2-20位'
                        },
                        remote:{
                            url:"hr/zz-department/checkAddDept",
                            delay:1000,
                            type:'post',
                            message:'部门名称已存在!',
                            data:function(validator){
                                return {
                                    'deptName':$("#deptName").val(),
                                    'oid':$("#oid").val(),
                                };
                            }
                        }
                    }
                },
                phone : {
                    validators : {
                        regexp : {
                            regexp : /^(^(\d{3,4}-)?\d{7,8})$|^((1[0-9][0-9]\d{8}$))$/,
                            message : '电话格式不正确'
                        }
                    }
                },
                email : {
                    validators : {
                        emailAddress : {
                            message : 'E-mail格式不正确'

                        }
                    }
                },
                fax : {
                    validators : {
                        regexp : {
                            regexp : /^(\d{3,4}-)?\d{7,8}$/,
                            message : '传真格式不正确'
                        }
                    }
                },
                zipcode : {
                    validators : {
                        regexp : {
                            regexp : /^[1-9]\d{5}$/,
                            message : '邮编格式不正确'
                        }
                    }
                },
                address : {
                    validators : {
                        stringLength : {
                            max : 200,
                            message : '地址输入过长'
                        }
                    }
                },
                description : {
                    validators : {
                        stringLength : {
                            max : 500,
                            message : '部门介绍输入过长'
                        }
                    }
                }
            },
            submitHandler : function(validator,form, submitButton) {
                validator.defaultSubmit();
            }
        });


        $("#resetbtn").click(function() {
            $("#myform").data("bootstrapValidator").resetForm();
        });
    });



</script>
</html>
